{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Distance: [2.54950976 2.54950976 2.41422468 ... 2.14595456 2.27999987 2.41536531]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<vedo.plotter.Plotter at 0x73eb48952de0>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"Compute the (signed) distance from one mesh to another.\"\"\"\n",
    "from vedo import *\n",
    "\n",
    "settings.default_backend = '2d' # or 2d, ipyvtk, or vtk\n",
    "\n",
    "s1 = Sphere().flat() # flat shading\n",
    "s2 = Cube(pos=(3,0,0), c='white', alpha=0.2)\n",
    "\n",
    "# add scalars to the sphere that correspond to their distance from the cube\n",
    "s1.distance_to(s2, signed=True, invert=False)\n",
    "s1.cmap(\"magma_r\").add_scalarbar()\n",
    "\n",
    "print(\"Distance:\", s1.pointdata[\"Distance\"])\n",
    "show(s1, s2, viewup='z', axes=1, bg='bb')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<tr>\n",
       "<td>\n",
       "<img src=''></img>\n",
       "</td>\n",
       "<td style='text-align: center; vertical-align: center;'><br/>\n",
       "<b> Sphere: &nbsp&nbsp</b><b><a href=\"https://vedo.embl.es/docs/vedo/mesh.html#Mesh\" target=\"_blank\">vedo.mesh.Mesh</a></b>\n",
       "<table>\n",
       "<tr><td><b> bounds </b> <br/> (x/y/z) </td><td>-0.9977 ... 0.9977<br/>-0.9977 ... 0.9977<br/>-1.000 ... 1.000</td></tr>\n",
       "<tr><td><b> center of mass </b></td><td>(0, 0, 0)</td></tr>\n",
       "<tr><td><b> average size </b></td><td>1.000</td></tr>\n",
       "<tr><td><b> nr. points&nbsp/&nbspfaces </b></td><td>1058&nbsp/&nbsp2112</td></tr>\n",
       "<tr><td><b> point data array </b></td><td>Distance</td></tr>\n",
       "\n",
       "</table>\n",
       "</table>"
      ],
      "text/plain": [
       "<vedo.shapes.Sphere at 0x73eb49ad72f0>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "distance_to\n",
       "├── Cube\n",
       "└── Sphere"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.pipeline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
